package com.geek.javase.ch13.work.singleton;

/*
 *@author wangpeng
 *2025/10/26 17:07
 *@description TODO
 */
import java.io.*;

public class Singleton implements Serializable {
    //私有构造函数，防止外部实例化
    private Singleton() {
    }
    //静态内部类
    private static class SingletonHolder {
        private static final Singleton instance = new Singleton();
    }
    // 提供全局访问点
    public static Singleton getInstance() {
        return SingletonHolder.instance;
    }

    // readResolve方法来防止破坏单例的情况
    private Object readResolve() {
        return SingletonHolder.instance;
    }
}

